package cn.edu.lcu.cs.javaprogramming.net;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author ling
 * @date 2022/11/12 12:52
 */
public class HelloClient {
    public static void main(String[] args) throws IOException {
        System.out.println("等待与服务器建立连接……");
        // 建立到服务器的连接，如果未连接就一直等待……
        Socket client = new Socket("localhost", 7788);
        // 获取来自服务器的输入流，并包装成带缓冲的字符流，方便读取文本
        BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
        String line = null;
        // 逐行读取，直到结束
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }

        System.out.println("数据传输结束");
        // 关闭各种资源
        reader.close();
        client.close();
    }
}
